/*
 * @Author: zhengzhuang
 * @since: 2020-02-29 15:10:59
 * @lastTime: 2020-03-01 14:38:09
 * @LastAuthor: zhengzhuang
 * @FilePath: /C20Driver/lib/pages/carpool_page/looking_passengers.dart
 * @message: 正在寻找乘客   LookingPassengers
 */
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:C20Driver/service/request.dart';
import 'package:C20Driver/widget/spinkit.dart';

class LookingPassengers extends StatefulWidget {
  LookingPassengers({this.id, this.orderId, this.depArea, this.destArea});
  final String id;
  final String orderId;
  final String depArea;
  final String destArea;
  @override
  _LookingPassengersState createState() => _LookingPassengersState();
}

class _LookingPassengersState extends State<LookingPassengers> {
  bool _updata = true;

  Future _getFellowList() async {
    return await Request.getLookingPassengersFun(widget.id);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('正在寻找乘客...'),
      ),
      body: Container(
        color: Color.fromARGB(255, 243, 244, 246),
        child: Column(
          children: <Widget>[
            Container(
              width: ScreenUtil().setWidth(750.0),
              height: ScreenUtil().setWidth(100.0),
              color: Colors.white,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: <Widget>[
                  Container(
                    width: ScreenUtil().setWidth(300.0),
                    child: Text(
                      widget.depArea,
                      textAlign: TextAlign.end,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(30.0),
                          color: Colors.black),
                    ),
                  ),
                  // SizedBox(width: ScreenUtil().setWidth(50.0)),
                  Text('==>'),
                  // SizedBox(width: ScreenUtil().setWidth(50.0)),
                  Container(
                    width: ScreenUtil().setWidth(300.0),
                    child: Text(
                      widget.destArea,
                      overflow: TextOverflow.ellipsis,
                      textAlign: TextAlign.start,
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(30.0),
                          color: Colors.black),
                    ),
                  ),
                ],
              ),
            ),
            Expanded(
              child: RefreshIndicator(
                onRefresh: () async {
                  setState(() {
                    _updata = true;
                  });
                },
                child: FutureBuilder(
                  future: _updata ? _getFellowList() : null,
                  builder: (BuildContext context, AsyncSnapshot snapshot) {
                    List dataSnap = snapshot.data;
                    if (snapshot.hasData && dataSnap.length != 0) {
                      return ListView.builder(
                        itemCount: dataSnap.length,
                        itemBuilder: (context, index) {
                          return Container(
                            margin: EdgeInsets.only(
                              left: ScreenUtil().setWidth(30.0),
                              right: ScreenUtil().setWidth(30.0),
                              top: ScreenUtil().setWidth(10.0),
                              bottom: ScreenUtil().setWidth(10.0),
                            ),
                            padding:
                                EdgeInsets.all(ScreenUtil().setWidth(20.0)),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(
                                    ScreenUtil().setWidth(20.0))),
                            child: Column(
                              children: <Widget>[
                                Container(
                                    child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: <Widget>[
                                    Row(
                                      children: <Widget>[
                                        ClipOval(
                                          child: Container(
                                            width: ScreenUtil().setWidth(100.0),
                                            height:
                                                ScreenUtil().setWidth(100.0),
                                            child: Image.network(
                                                dataSnap[index]['headimgurl']),
                                          ),
                                        ),
                                        SizedBox(
                                            width: ScreenUtil().setWidth(20.0)),
                                        Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: <Widget>[
                                            Text(
                                                '${dataSnap[index]['passenger_name']}',
                                                style: TextStyle(
                                                    fontSize: ScreenUtil()
                                                        .setSp(32.0),
                                                    color: Colors.black)),
                                            SizedBox(
                                                height: ScreenUtil()
                                                    .setWidth(10.0)),
                                            Text(
                                                '顺路程度${dataSnap[index]["road_level"]}%',
                                                style: TextStyle(
                                                    fontSize: ScreenUtil()
                                                        .setSp(26.0),
                                                    color: Color.fromARGB(
                                                        255, 34, 147, 255))),
                                          ],
                                        ),
                                      ],
                                    ),
                                    RichText(
                                        text: TextSpan(
                                            text: '￥',
                                            style: TextStyle(
                                                fontSize:
                                                    ScreenUtil().setSp(30.0),
                                                color: Colors.black),
                                            children: <TextSpan>[
                                          TextSpan(
                                              text:
                                                  '${dataSnap[index]["total_price"]}',
                                              style: TextStyle(
                                                  fontSize:
                                                      ScreenUtil().setSp(60.0),
                                                  color: Colors.black)),
                                        ])),
                                  ],
                                )),
                                SizedBox(height: ScreenUtil().setWidth(10.0)),
                                Divider(height: ScreenUtil().setWidth(1.0)),
                                SizedBox(height: ScreenUtil().setWidth(10.0)),
                                Container(
                                  child: Row(
                                    children: <Widget>[
                                      ClipOval(
                                        child: Container(
                                          width: ScreenUtil().setWidth(13.0),
                                          height: ScreenUtil().setWidth(13.0),
                                          color: Color.fromARGB(
                                              255, 102, 102, 102),
                                        ),
                                      ),
                                      SizedBox(
                                          width: ScreenUtil().setWidth(8.0)),
                                      Text(
                                          '${dataSnap[index]["departure_date"]} · ${dataSnap[index]["people_number"]}人',
                                          style: TextStyle(
                                              fontSize:
                                                  ScreenUtil().setSp(30.0),
                                              color: Colors.black45))
                                    ],
                                  ),
                                ),
                                SizedBox(height: ScreenUtil().setWidth(10.0)),
                                Container(
                                  width: ScreenUtil().setWidth(650.0),
                                  child: Row(
                                    children: <Widget>[
                                      ClipOval(
                                        child: Container(
                                          width: ScreenUtil().setWidth(13.0),
                                          height: ScreenUtil().setWidth(13.0),
                                          color:
                                              Color.fromARGB(255, 36, 142, 247),
                                        ),
                                      ),
                                      SizedBox(
                                          width: ScreenUtil().setWidth(8.0)),
                                      Container(
                                        width: ScreenUtil().setWidth(600.0),
                                        child: Text(
                                            '${dataSnap[index]["dep_are"]}',
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                                fontSize:
                                                    ScreenUtil().setSp(30.0),
                                                color: Colors.black45)),
                                      ),
                                    ],
                                  ),
                                ),
                                SizedBox(height: ScreenUtil().setWidth(10.0)),
                                Container(
                                  child: Row(
                                    children: <Widget>[
                                      ClipOval(
                                        child: Container(
                                          width: ScreenUtil().setWidth(13.0),
                                          height: ScreenUtil().setWidth(13.0),
                                          color:
                                              Color.fromARGB(255, 255, 102, 0),
                                        ),
                                      ),
                                      SizedBox(
                                          width: ScreenUtil().setWidth(8.0)),
                                      Container(
                                        width: ScreenUtil().setWidth(600.0),
                                        child: Text(
                                            '${dataSnap[index]["dest_area"]}',
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                                fontSize:
                                                    ScreenUtil().setSp(30.0),
                                                color: Colors.black45)),
                                      ),
                                    ],
                                  ),
                                ),
                                SizedBox(height: ScreenUtil().setWidth(10.0)),
                                Divider(height: ScreenUtil().setWidth(1.0)),
                                SizedBox(height: ScreenUtil().setWidth(10.0)),
                                Container(
                                  child: Row(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: <Widget>[
                                      Text('正在寻找车主...',
                                          style: TextStyle(
                                              fontSize:
                                                  ScreenUtil().setSp(28.0),
                                              color: Colors.black26)),
                                      InkWell(
                                        child: Container(
                                          width: ScreenUtil().setWidth(160.0),
                                          height: ScreenUtil().setWidth(65.0),
                                          alignment: Alignment.center,
                                          decoration: BoxDecoration(
                                              border: Border.all(
                                                  width: ScreenUtil()
                                                      .setWidth(2.0),
                                                  color: Color.fromARGB(
                                                      255, 255, 153, 51)),
                                              borderRadius:
                                                  BorderRadius.circular(
                                                      ScreenUtil()
                                                          .setWidth(10.0))),
                                          child: Text(
                                            '捎上乘客',
                                            style: TextStyle(
                                              fontSize:
                                                  ScreenUtil().setSp(30.0),
                                              color: Color.fromARGB(
                                                  255, 255, 153, 0),
                                            ),
                                          ),
                                        ),
                                        // onTap: () {
                                        //   print(dataSnap[index]["id"]);
                                        //   print(widget.id);
                                        // },
                                        onTap: () =>
                                            Request.driverArriveBoardingPoint(
                                                cId: dataSnap[index]["id"],
                                                sjId: widget.id,
                                                context: context),
                                        // onTap: () => NavigatorUtil.jump(context, '/takePassengers?id=${dataSnap[index]["id"]}&orderId=${widget.orderId}'),
                                      ),
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          );
                        },
                      );
                    } else {
                      return Spinkit();
                    }
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
